#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;
#define x first
#define y second

const int N = 2e5 + 5;
const int M = 1e9+7;

string s;
ll k;

set<pii> S;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    
    cin >> s >> k;

    int a = 0, b = 0;
    S.insert({0, 0});
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'U') b--;
        else if (s[i] == 'D') b++;
        else if (s[i] == 'R') a++;
        else a--;

        S.insert({a, b});
    }
    
    // 转了一圈回到原点，只能扫走V中的点
    if (a == 0 && b == 0) {
        cout << S.size() << endl;
        return 0;
    }

    vector<pii> V;
    for (auto& p : S) V.push_back(p);
    // (a, b)放到第一象限
    if (a < 0) {
        a = -a;
        for(auto& p : V) p.x = -p.x;
    }

    if (b < 0) {
        b = -b;
        for (auto& p : V) p.y = -p.y;
    }

    if (a == 0) {
        swap(a, b);
        for (auto& p : V) swap(p.x, p.y);
    }
    // 按(si, ti)对V分组
    map<pii, vector<pii>> grp;

    for (auto& p : V) {
        int xi = p.x, yi = p.y;
        int qi = xi/a, si = xi-qi*a, ti = yi-qi*b;

        if (si < 0) si += a, ti += b;
        grp[{si, ti}].push_back(p);
    }

    ll res = 0;

    for (auto& [_, val] : grp) {
        // auto val = it.y;
        sort(val.begin(), val.end());
        for (int i = 1; i < val.size(); i++) {
            int temp1 = (val[i].x - val[i-1].x)/a;
            ll temp = min(k, (ll)temp1);
            res += (ll)temp;
        }
        res += k;
    }

    cout << res << endl;
    return 0;
}
